//
//  ACWBillCheckVC.m
//  aichewang
//
//  Created by rylynn lai on 16/2/24.
//  Copyright © 2016年 aichewang. All rights reserved.
//

#import "ACWBillCheckVC.h"
#import "ACWBillListVC.h"

@interface ACWBillCheckVC ()
@property (nonatomic, strong) UIDatePicker *datePicker;
@property (weak, nonatomic) IBOutlet UITextField *startDateTF;
@property (weak, nonatomic) IBOutlet UITextField *endDateTF;
@property (weak, nonatomic) IBOutlet UIButton *billCheckBtn;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomConstraint;

@end

@implementation ACWBillCheckVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"账单查询";
    self.autoHiddenKeyBoardEnable = YES;
    _startDateTF.inputView = self.datePicker;
    _endDateTF.inputView = self.datePicker;
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pickerShowUp:) name:UITextFieldTextDidBeginEditingNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pickerDismiss:) name:UITextFieldTextDidEndEditingNotification object:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



- (UIDatePicker *)datePicker {
    if (!_datePicker) {
        _datePicker = [[UIDatePicker alloc] init];
        _datePicker.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];
        [_datePicker addTarget:self action:@selector(dateSelect:) forControlEvents:UIControlEventValueChanged];
    }
    return _datePicker;
}
- (IBAction)billCheckClick {
    ACWBillListVC *billListVC = [[ACWBillListVC alloc] init];
    self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:billListVC animated:YES];
    self.hidesBottomBarWhenPushed = NO;
}

- (void)dateSelect:(UIDatePicker *)datePicker {
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init] ;
    [formatter setDateFormat:@"MM-dd HH:mm"];
    if ([_startDateTF isFirstResponder]) {
        _startDateTF.text = [NSString stringWithFormat:@"开始时间:   %@", [formatter stringFromDate:datePicker.date]];
    } else if ([_endDateTF isFirstResponder]) {
        _endDateTF.text = [NSString stringWithFormat:@"结束时间:   %@", [formatter stringFromDate:datePicker.date]];
    }
}

- (void)pickerShowUp:(NSNotification *)notification {
    _bottomConstraint.constant += _datePicker.height;
}

- (void)pickerDismiss:(NSNotification *)notification {
    self.hidesBottomBarWhenPushed = YES;
    _bottomConstraint.constant = 0;
    self.hidesBottomBarWhenPushed = NO;
}


@end
